package 安全区;

import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static int N = 3010;
    static int[][] g = new int[N][N];
    static int[][] f = new int[N][N];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int T = in.nextInt();
        for (int cases = 1; cases <= T; cases++) {
            int r = in.nextInt();
            int c = in.nextInt();
            int k = in.nextInt();
            for (int i = 0; i <=r; i++) {
                Arrays.fill(g[i], 0);
                Arrays.fill(f[i], 0);

            }
            for (int i = 0; i < k; i++) {
                int x = in.nextInt();
                int y = in.nextInt();
                g[x + 1][y + 1] = 1;
            }
            for (int i = 1; i <= r; i++) {
                for (int j = 1; j <= c; j++) {
                    if (g[i][j] != 1) {
                        f[i][j] = Math.min(f[i - 1][j - 1], Math.min(f[i][j - 1], f[i - 1][j])) + 1;
                    }
                }
            }
            long res = 0;
            for (int i = 1; i <= r; i++) {
                for (int j = 1; j <= c; j++) {
                    res += f[i][j];
                }
            }
            System.out.printf("Case #%d: %d\n", cases, res);
        }
    }
}
